﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BSCMFF.Core.DataAccessLayer;
using Telerik.Web.UI;

namespace BSCMFF.Web.Pages
{
    public partial class EmployeeInfo : BSCMFF.Core.MultiLanguagePage
    {
        protected User u;
        private BSCEntities context;
        public string ss = "tralala";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["EmployeeID"] == null)
            {
                Response.Redirect("EmployeeInfo.aspx?EmployeeID=5");
            }
            int employeerID = Convert.ToInt32(Request.QueryString["EmployeeID"]);
           // LabelName.Text = s;

            //if (!IsPostBack)
            //{
                context = new BSCEntities();
                u = (from user in context.Users
                     //where user.Login == User.Identity.Name
                     where user.ID == employeerID
                     select user).Single();

                //EmployeeName.Text = u.Login;// u.Firstname + u.Lastname;
                //if (u.Photo != null)
                //{
                //    RadBinaryImage1.DataValue = u.Photo;
                //}
                //else
                //{
                //    RadBinaryImage1.ImageUrl = "~/Images/silhouette/silhouette-stewie.jpg";
                    
                //}

                List<User> users = new List<User>();
                users.Add(u);
                //RadListView1.DataSource = users;
                //RadListView1.DataBind();
                Page.DataBind();
           // }
        }

        protected void ButtonUploadImage_Click(object sender, EventArgs e)
        {
            RadUpload RadUpload1 = new RadUpload() ;// = RadListView1.Controls.
            if (RadUpload1.UploadedFiles.Count == 1)
            {


                long length = RadUpload1.UploadedFiles[0].InputStream.Length;
                //u.Photo = new byte[length];
                byte[] buff = new byte[length];
                RadUpload1.UploadedFiles[0].InputStream.Read(buff, 0, (int)length);
                //RadUploadImage.UploadedFiles[0].

                u.Photo = buff;

                context.SaveChanges();
                //RadBinaryImage1.DataValue = u.Photo;
               // RadListView1.DataBind();
            }
        }
    }
}